package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.News;
import cn.wolfcode.trip.base.domain.Strategy;
import cn.wolfcode.trip.base.query.NewsQueryObject;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.INewsService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("news")
public class NewsController {

    @Autowired
    private INewsService newsService;

    /**
     * 列出所有日报
     * @param qo
     * @return
     */
    @GetMapping
    public PageInfo query(NewsQueryObject qo){
        //按照推荐时间倒序排列
        qo.setOrderBy("n.commendTime desc");
        return newsService.listAll(qo);
    }
    /**
     * 根据id获取日报详情内容
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public News getById(@PathVariable Long id){

        return newsService.getById(id);
    }
}
